/*
 * Singularity Engine
 * Copyright (C) 2010 Vyacheslav Vorobyov, All rights reserved.
 * See LICENSE for full license information.
 */
package org.singularity.lang.model;

import java.util.ArrayList;
import java.util.List;

/**
 * @author vjache
 *
 */
public abstract class TuplePattern {
	
	public abstract class SlotPattern
	{	
		public SlotPattern()
		{_slots.add(this);}
		
		private final List<String> _fqn = new ArrayList<String>(3);
		public List<String> getFqn() 
		{return _fqn;}
		public abstract void toString(StringBuilder sb, String string);
	}
	
	public class ConstSlotPattern extends SlotPattern
	{
		private final Object _const;

		public ConstSlotPattern(Object aConst) 
		{_const = aConst;}
		public Object getConst() 
		{return _const;}
		@Override
		public void toString(StringBuilder sb, String shift) {
			sb.append(shift)
			.append("SLOT(CONST):");
			if(getFqn()!=null)
				sb.append("FQN=").append(getFqn()).append(", ");
			sb.append("EXPR=").append(_const);
		}
		
	}
	public class VariableSlotPattern extends SlotPattern
	{
		private final String _variableName;
		
		public VariableSlotPattern(String aVarName) 
		{_variableName = aVarName;}
		public String getVariableName() 
		{return _variableName;}
		@Override
		public void toString(StringBuilder sb, String shift) {
			sb.append(shift)
			.append("SLOT(VAR):");
			if(getFqn()!=null)
				sb.append("FQN=").append(getFqn()).append(", ");
			sb.append("EXPR=").append(_variableName);
		}
	}
	
	private final List<SlotPattern> _slots = new ArrayList<SlotPattern>(5);

	/**
	 * 
	 */
	public TuplePattern() {}

	/**
	 * @return the slots
	 */
	public List<SlotPattern> getSlots() {
		return _slots;
	}

	public void toString(StringBuilder sb, String shift) {
		sb.append(shift).append("TUPLE PATTERN").append(StringUtil.NL);
		for(SlotPattern sl:_slots)
		{
			sl.toString(sb,shift+StringUtil.TAB);
			sb.append(StringUtil.NL);
		}
	}

}
